home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / deletePanel.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.1 KB  |  181 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Feb 18 1996
  22. //  Author:         cdg
  23. //
  24. //  Description:
  25. //        Delete a panel.  If it is visible replace it with another panel.
  26. //        If it is torn off then also delete its window.
  27. //
  28. //  Input Arguments:
  29. //      $whichPanel:  The name of the panel to be deleted.
  30. //
  31. //  Return Value:
  32. //      None.
  33. //
  34. //    Note:
  35. //        None.
  36. // 
  37.  
  38.  
  39. global proc deletePanel (string $whichPanel) {
  40. //
  41. //  Description:
  42. //        Delete a panel.  If it is visible replace it with another panel.
  43. //        If it is torn off then also delete its window.
  44. //
  45. //
  46.     global string $gMainPane;
  47.     global string $gPanelEditorWnd;
  48.  
  49.     string $winName;
  50.     string $panelControl;
  51.     string $p1,$p2,$p3,$p4;
  52.     string $msg;
  53.     int    $pane = 0;
  54.     int       $nVisPanes;
  55.     string $panels[];
  56.     string $controls[];
  57.  
  58.     if (`panel -exists $whichPanel`) {
  59.         //
  60.         //  First check to confirm that this wasn't a mistake.
  61.         //
  62.         $msg = ("Are you sure you want to permanently delete '" + $whichPanel + "'?");
  63.         if ("OK" == `confirmDialog -title "Confirm" -message $msg
  64.             -button "OK" -button "Cancel" -defaultButton "OK"
  65.             -cancelButton "Cancel" -dismissString "Cancel"
  66.             -parent $gPanelEditorWnd`) 
  67.         {
  68.             //
  69.             //  Okay to delete.
  70.             //
  71.             if (`panel -q -to $whichPanel`) {
  72.                 //
  73.                 //  panel is torn off so get rid of its window first.
  74.                 //
  75.                 $winName = match("^[^|]*",`panel -q -control $whichPanel`);
  76.                 deleteUI -window $winName;
  77.  
  78.             } else {
  79.                 $panelControl =  `panel -q -control $whichPanel`;
  80.                 if ("" != $panelControl) {
  81.                     $panelControl = match("[^|]*$",$panelControl);
  82.                     //  
  83.                     //  Panel is parented.  Assume that it is in the main pane
  84.                     //  since it is not torn off.
  85.                     //
  86.                     $p1 = `paneLayout -q -p1 $gMainPane`;
  87.                     $p2 = `paneLayout -q -p2 $gMainPane`;
  88.                     $p3 = `paneLayout -q -p3 $gMainPane`;
  89.                     $p4 = `paneLayout -q -p4 $gMainPane`;
  90.                     $nVisPanes = `paneLayout -q -nvp $gMainPane`;
  91.  
  92.                     if ($panelControl == $p1) {
  93.                         $pane = 1;
  94.                     } else if ($panelControl == $p2 && $nVisPanes > 1) {
  95.                         $pane = 2;
  96.                     } else if ($panelControl == $p3 && $nVisPanes > 2) {
  97.                         $pane = 3;
  98.                     } else if ($panelControl == $p4 && $nVisPanes > 3) {
  99.                         $pane = 4;
  100.                     }
  101.                     if ($pane > 0) {
  102.                         //
  103.                         //  Panel is in one of the visible main panes, so
  104.                         //  it should be replaced with something else.
  105.                         //
  106.  
  107.                         //
  108.                         //      First try to replace with something that is already
  109.                         //        parented to the same paneLayout.
  110.                         //
  111.                         string $replacementPanel = "";
  112.                         string $cmdStr;
  113.  
  114.                         $controls = `paneLayout -q -ca $gMainPane`;
  115.                         for ($control in $controls) {
  116.                             if ($control != $panelControl && 
  117.                                 $control != $p1 && 
  118.                                 ($nVisPanes < 2 || $control != $p2) &&
  119.                                 ($nVisPanes < 3 || $control != $p3) && 
  120.                                 ($nVisPanes < 4 || $control != $p4)
  121.                                 ) 
  122.                             {
  123.                                 $replacementPanel = `getPanel -containing $control`;
  124.                                 if ("" != $replacementPanel) {
  125.                                     break;
  126.                                 }
  127.                             }
  128.                         }
  129.  
  130.                         if ("" == $replacementPanel) {
  131.                             //
  132.                             //  Try to parent an unparented panel.
  133.                             //
  134.                             $panels = `getPanel -allPanels`;
  135.                             for ($panel in $panels) {
  136.                                 if ("" == `panel -q -control $panel`) {
  137.                                     $replacementPanel = $panel;
  138.                                     break;
  139.                                 }
  140.                             }
  141.                         }
  142.  
  143.                         if ("" == $replacementPanel) {
  144.                             //
  145.                             //  Make an new model panel to fill the spot.
  146.                             //
  147.                             $replacementPanel = `modelPanel -unParent`;
  148.                             modelPanel -e 
  149.                                 -label `interToUI $replacementPanel`
  150.                                 $replacementPanel;
  151.  
  152.                         }
  153.  
  154.                         if ("" == `panel -q -control $replacementPanel`) {
  155.                             //
  156.                             //  parent it to the main pane layout.
  157.                             //
  158.                             $cmdStr = `getPanel -typeOf $replacementPanel`;
  159.                             $cmdStr += (" -e -parent $gMainPane " + $replacementPanel);
  160.                             eval $cmdStr;
  161.                         }
  162.  
  163.                         //
  164.                         //  Move it to the correct pane.
  165.                         //
  166.                         paneLayout -e 
  167.                             -sp `panel -q -control $replacementPanel` $pane
  168.                             $gMainPane;
  169.                     }
  170.                 }
  171.             }
  172.  
  173.             //  Finally, delete the panel.
  174.             //
  175.             deleteUI -panel $whichPanel;
  176.         }
  177.     } else {
  178.         warning("Unable to delete '"+ $whichPanel +"'.  Panel not Found.");
  179.     }
  180. }
  181.